<template>
  <div class="app-container">
    <el-form :model="searchForm" label-width="80px" @keyup.enter.native="search()">
      <el-row>
        <el-col class="other">
          <el-form-item label="人员姓名" size="small">
            <el-input v-model="searchForm.name"></el-input>
          </el-form-item>
        </el-col>
        <!--<el-col class="other">-->
        <!--<el-form-item label="团队名称" size="small">-->
        <!--<el-input v-model="searchForm.teamName"></el-input>-->
        <!--</el-form-item>-->
        <!--</el-col>-->
        <el-col class="searchBtn">
          <el-form-item size="small">
            <el-button type="primary" icon="el-icon-search" @click="search()">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="table-btn">
      <el-button type="primary" size="small" icon="el-icon-plus" @click="addTeam()">添加</el-button>
      <el-button type="primary" size="small" icon="el-icon-upload2" @click="downloadFile">导入</el-button>
      <input class="file" type="file" @change="fileChanged" ref="file"/>
      <!--<el-button size="small" icon="el-icon-upload2">导出</el-button>-->
      <el-dialog :title="dialogTitle" :visible.sync="outerVisible" width="850px">
        <el-form ref="teamRow" :rules="rules" :model="teamRow" label-width="110px">
          <el-row>
            <el-col class="dialog-line">
              <el-form-item label="所属团队" size="small">
                <!--<el-autocomplete-->
                <!--v-model="teamRow.teamName"-->
                <!--:fetch-suggestions="querySearchTeam"-->
                <!--@select="handleSelectTeam"-->
                <!--placeholder="请输入内容"-->
                <!--&gt;-->
                <!--</el-autocomplete>-->
                <el-input type="text" v-model="teamRow.teamName" disabled></el-input>
              </el-form-item>
              <el-form-item prop="amount" label="工资" size="small">
                <el-input type="number" v-model.number="teamRow.amount">
                  <span slot="suffix">元</span>
                </el-input>
              </el-form-item>
              <el-form-item prop="socialInsuranceBase" label="社保基数" size="small">
                <el-input type="number" v-model.number="socialInsuranceBase">
                  <span slot="suffix">元</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="name" label="员工姓名" size="small">
                <el-autocomplete
                  v-model="teamRow.name"
                  :fetch-suggestions="querySearchName"
                  @select="handleSelectName"
                  placeholder="请输入内容"
                >
                </el-autocomplete>
              </el-form-item>
              <el-form-item prop="compensationTime" label="调薪时间" size="small">
                <el-date-picker
                  v-model="teamRow.compensationTime"
                  type="date"
                  value-format="timestamp"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>

            </el-col>
          </el-row>
          <el-row>
            <el-col class="dialog-line">
              <el-form-item prop="restCoefficient" label="养老保险系数" size="small">
                <el-input type="number" v-model.number="restCoefficient">
                </el-input>
              </el-form-item>
              <el-form-item prop="medicalTreatmentCoefficient" label="医疗保险系数" size="small">
                <el-input type="number" v-model.number="medicalTreatmentCoefficient">
                </el-input>
              </el-form-item>
              <el-form-item prop="unemploymentCoefficient" label="失业保险系数" size="small">
                <el-input type="number" v-model.number="unemploymentCoefficient">
                </el-input>
              </el-form-item>
              <el-form-item label="工伤保险" size="small">
                {{teamRow.workInsurance}}元
              </el-form-item>
              <el-form-item prop="providentFundBase" label="公积金基数" size="small">
                <el-input type="number" v-model.number="providentFundBase">
                  <span slot="suffix">元</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item label="养老保险" size="small">
                {{teamRow.endowmentInsurance}}元
              </el-form-item>
              <el-form-item label="医疗保险" size="small">
                {{teamRow.doctorInsurance}}元
              </el-form-item>
              <el-form-item label="失业保险" size="small">
                {{teamRow.unemploymentInsurance}}元
              </el-form-item>
              <el-form-item label="生育保险" size="small">
                {{teamRow.maternity}}元
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col class="dialog-line">
              <el-form-item prop="providentFundCoefficient" label="公积金系数" size="small">
                <el-input type="number" v-model.number="providentFundCoefficient">
                </el-input>
              </el-form-item>
              <el-form-item label="残疾人保障险" size="small">
                <el-input type="number" v-model.number="teamRow.disabilityBenefits"></el-input>
              </el-form-item>
              <el-form-item prop="welfareFee" label="福利" size="small">
                <el-input type="number" v-model.number="teamRow.welfareFee"></el-input>
              </el-form-item>
              <el-form-item prop="datePay" label="发放时间" size="small">
                <el-date-picker
                  v-model="teamRow.datePay"
                  type="date"
                  value-format="timestamp"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item label="住房公积金" size="small">
                {{teamRow.housingFund}}元
              </el-form-item>
              <el-form-item label="工会经费" size="small">
                <el-input type="number" v-model.number="teamRow.unionExpenditure"></el-input>
              </el-form-item>
              <el-form-item label="个税" size="small">
                <el-input type="number" v-model.number="teamRow.individualincometax"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item v-if="!dialogType" size="small">
            <el-button type="warning" size="small"  @click="submitForm('teamRow')" v-no-more-click>
              保存
            </el-button>
          </el-form-item>
        </el-form>
        <el-form v-if="!dialogType" :model="monthForm" label-width="80px">
          <el-row>
            <el-col class="datePicker">
              <el-form-item label="时间区间" size="small">
                <el-date-picker type="date" placeholder="选择开始日期" value-format="timestamp"
                                v-model="monthForm.startTime"
                ></el-date-picker>
                <span>-</span>
                <el-date-picker type="date" placeholder="选择结束日期" value-format="timestamp"
                                v-model="monthForm.endTime"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="searchBtn">
              <el-form-item size="small">
                <el-button type="primary" icon="el-icon-search" @click="searchMonthForm()">搜索</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <my-table
          v-if="!dialogType"
          :data="scheduleData"
          :col-configs="scheduleConfigs"
          v-loading="scheduleLoading"
          :height="200"
        >
          <el-table-column
            slot="scheduleOpt"
            fixed="right"
            label="操作"
            width="150">
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="selectSchedule(scope.row.personId)"
                type="text"
                size="small">
                查看
              </el-button>
            </template>
          </el-table-column>
        </my-table>
        <div v-if="dialogType" slot="footer" class="dialog-footer">
          <el-button type="warning" size="small"  @click="submitForm('teamRow')" v-no-more-click>确定</el-button>
          <el-button size="small" @click="outerVisible = false">取消</el-button>
        </div>
        <el-dialog width="500px" title="查看人员工资" :visible.sync="innerVisible" append-to-body>
          <el-form ref="MonthlyWages" :model="MonthlyWages" class="inner-dialog" label-width="110px">
            <el-form-item label="所属团队" size="small" class="item-inline">
              {{MonthlyWages.teamName}}
            </el-form-item>
            <el-form-item label="姓名" size="small" class="item-inline">
              {{MonthlyWages.personName}}
            </el-form-item>
            <el-form-item label="职级" size="small" class="item-inline">
              <el-select v-model="MonthlyWages.rank" placeholder="请选择">
                <el-option
                  v-for="item in global.rankList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="薪资" size="small" class="item-inline">
              {{MonthlyWages.pay}}元
            </el-form-item>
            <el-form-item label="基本工资" size="small">
            </el-form-item>
            <el-form-item label="金额" size="small" class="item-inline">
              {{MonthlyWages.basicMoney}}元
            </el-form-item>
            <el-form-item label="占比" size="small" class="item-inline">
              {{MonthlyWages.basicProportion}}元
            </el-form-item>
            <el-form-item label="绩效工资" size="small">
            </el-form-item>
            <el-form-item label="金额" size="small" class="item-inline">
              {{MonthlyWages.performanceMoney}}元
            </el-form-item>
            <el-form-item label="占比" size="small" class="item-inline">
              {{MonthlyWages.performanceProportion}}元
            </el-form-item>
            <el-form-item label="系数" size="small" class="item-inline">
              {{MonthlyWages.coefficient}}元
            </el-form-item>
            <el-form-item label="得分" size="small" class="item-inline">
              {{MonthlyWages.score}}元
            </el-form-item>
            <el-form-item label="实得" size="small" class="item-inline">
              {{MonthlyWages.realization}}元
            </el-form-item>
            <el-form-item label="各项补贴" size="small">
            </el-form-item>
            <el-form-item label="交通/餐饮补贴" size="small" class="item-inline">
              {{MonthlyWages.trafficSubsidy}}元
            </el-form-item>
            <el-form-item label="其他" size="small" class="item-inline">
              {{MonthlyWages.otherSubsidy}}元
            </el-form-item>
            <el-form-item label="季度奖金" size="small" class="item-inline">
              {{MonthlyWages.quarterlyBonus}}元
            </el-form-item>
            <el-form-item label="迟到" size="small" class="item-inline">
              {{MonthlyWages.late}}元
            </el-form-item>
            <el-form-item label="缺勤" size="small" class="item-inline">
              {{MonthlyWages.absence}}元
            </el-form-item>
            <el-form-item label="事假" size="small" class="item-inline">
              {{MonthlyWages.workHoliday}}元
            </el-form-item>
            <el-form-item label="病假" size="small" class="item-inline">
              {{MonthlyWages.sickLeave}}元
            </el-form-item>
            <el-form-item label="旷工" size="small" class="item-inline">
              {{MonthlyWages.absenteeism}}元
            </el-form-item>
            <el-form-item label="常规补贴扣款" size="small" class="item-inline">
              {{MonthlyWages.subsidyCost}}元
            </el-form-item>
            <el-form-item label="社保" size="small" class="item-inline">
              {{MonthlyWages.socialSecurity}}元
            </el-form-item>
            <el-form-item label="公积金" size="small" class="item-inline">
              {{MonthlyWages.providentFund}}元
            </el-form-item>
            <el-form-item label="个税" size="small" class="item-inline">
              {{MonthlyWages.personTax}}元
            </el-form-item>
          </el-form>
        </el-dialog>
      </el-dialog>
    </div>
    <my-table
      :data="tableData"
      :col-configs="colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
    >
      <el-table-column
        slot="opt"
        fixed="right"
        label="操作"
        width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="editTeam(scope.row)"
            type="text"
            size="small">
            修改
          </el-button>
          <el-popover
            placement="top"
            width="160"
            :ref="`popover-${scope.$index}`"
          >
            <p>确定删除这条数据吗?</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[`popover-${scope.$index}`].doClose()">取消</el-button>
              <el-button type="primary" size="mini" @click.native.prevent="deleteRow(scope)">确定</el-button>
            </div>
            <el-button type="text" size="small" slot="reference" v-popover:popover-${scope.$index}>删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
  import {
    addEmployeePay,
    deleteEmployeePay,
    downloadMonthlyWages,
    getEmployeePayList,
    getMonthlyWages,
    selectEmployeePay,
    selectEmployees,
    selectMonthlyWages,
    selectTeam,
    updateEmployeePay
  } from '@/api/employeepay'
  import myTable from '@/components/myTable'
  import global from '@/components/global'

  import { Message } from 'element-ui'
  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'

  const datePay = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const time = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        if (time) {
          var date = new Date(time)
          return formatDate(date, 'yyyy-MM-dd')
        }
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const amount = {
    props: ['colConfig'],
    mounted() {
      console.log(this.colConfig)
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
        <el-table-column v-for="(item, index) in colConfig.children"  :label="item.label" :width="item.width">
                    <span slot-scope="scope">{{scope.row[item.prop]}}</span>
        </el-table-column>
    </el-table-column>
  `
  }

  const formatter = function(row, column) {
    if (row[column.property]) {
      let obj = {}
      obj = global[`${column.property}List`].find((item) => {
        return item.value === row[column.property] // 筛选出匹配数据
      })
      return obj.label
    }
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    data() {
      return {
        colConfigs: [
          { prop: 'teamName', label: '所属团队', width: '200', fixed: true },
          { prop: 'name', label: '员工姓名', width: '100' },
          { prop: 'amount', label: '工资', width: '150' },
          { prop: 'compensationTime', label: '调薪时间', width: '150', component: time },
          { prop: 'socialInsuranceBase', label: '社保基数', width: '150' },
          { prop: 'restCoefficient', label: '养老保险系数', width: '150' },
          { prop: 'endowmentInsurance', label: '养老保险', width: '150' },
          { prop: 'medicalTreatmentCoefficient', label: '医疗保险系数', width: '150' },
          { prop: 'doctorInsurance', label: '医疗保险', width: '150' },
          { prop: 'unemploymentCoefficient', label: '失业保险系数', width: '150' },
          { prop: 'unemploymentInsurance', label: '失业保险', width: '150' },
          { prop: 'workInsurance', label: '工伤保险', width: '150' },
          { prop: 'maternity', label: '生育保险', width: '150' },
          { prop: 'providentFundBase', label: '公积金基数', width: '150' },
          { prop: 'providentFundCoefficient', label: '住房公积金系数', width: '150' },
          { prop: 'housingFund', label: '住房公积金', width: '150' },
          { prop: 'disabilityBenefits', label: '残疾人保障金', width: '150' },
          { prop: 'unionExpenditure', label: '工会经费', width: '150' },
          { prop: 'welfareFee', label: '福利', width: '150' },
          { prop: 'individualincometax', label: '个税', width: '150' },
          { prop: 'datePay', label: '发放月份', width: '150', component: datePay },
          { slot: 'opt' }
        ],
        scheduleConfigs: [
          { prop: 'teamName', label: '部门名称', width: '150', fixed: true },
          { prop: 'personName', label: '员工姓名', width: '100', fixed: true },
          { prop: 'idNumber', label: '身份证', width: '150' },
          { prop: 'rank', label: '职级', width: '150', formatter: formatter },
          { prop: 'pay', label: '薪资', width: '100' },
          {
            label: '基础工资', width: '200', children: [
              { prop: 'basicMoney', label: '金额', width: '100' },
              { prop: 'basicProportion', label: '占比', width: '100' }
            ], component: amount
          },
          {
            label: '绩效工资', width: '500', children: [
              { prop: 'performanceMoney', label: '金额', width: '100' },
              { prop: 'performanceProportion', label: '占比', width: '100' },
              { prop: 'score', label: '得分', width: '100' },
              { prop: 'coefficient', label: '系数', width: '100' },
              { prop: 'realization', label: '实得', width: '100' }
            ], component: amount
          },
          { prop: 'quarterlyBonus', label: '季度奖金', width: '100' },
          {
            label: '各项补贴', width: '500', children: [
              { prop: 'trafficSubsidy', label: '交通/餐饮补贴', width: '150' },
              { prop: 'otherSubsidy', label: '其他', width: '100' }
            ], component: amount
          },
          {
            label: '其他扣款', width: '500', children: [
              { prop: 'late', label: '迟到', width: '100' },
              { prop: 'absence', label: '缺勤', width: '100' },
              { prop: 'workHoliday', label: '事假', width: '100' },
              { prop: 'sickLeave', label: '病假', width: '100' },
              { prop: 'absenteeism', label: '旷工', width: '100' },
              { prop: 'subsidyCost', label: '常规补贴扣款', width: '150' },
              { prop: 'otherSubsidyCost', label: '其他', width: '100' }
            ], component: amount
          },
          {
            label: '代扣', width: '500', children: [
              { prop: 'socialSecurity', label: '社保', width: '100' },
              { prop: 'providentFund', label: '公积金', width: '100' },
              { prop: 'personTax', label: '个税', width: '100' }
            ], component: amount
          },
          { prop: 'netPayroll', label: '实发', width: '100' },
          { prop: 'moneyTime', label: '时间', width: '150', component: time },
          { slot: 'scheduleOpt' }
        ],
        searchForm: {},
        searchFormList: {},
        monthForm: {},
        listLoading: true,
        scheduleLoading: true,
        dialogTitle: '新增人员工资支出',
        dialogType: 0,
        teamRow: {},
        teamRowClear: {},
        tableData: [],
        scheduleData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        outerVisible: false,
        innerVisible: false,
        pca: pca,
        rules: {
          teamName: [
            { required: true, message: '请输入团队名称', trigger: 'change' }
          ],
          name: [
            { required: true, message: '请输入员工', trigger: 'change' }
          ],
          amount: [
            { required: true, message: '请输入工资', trigger: 'change' }
          ],
          compensationTime: [
            { required: true, message: '请选择调薪时间', trigger: 'change' }
          ],
          socialInsuranceBase: [
            { required: true, message: '请输入社保缴费基数', trigger: 'change' }
          ],
          restCoefficient: [
            { required: true, message: '请输入养老保险系数', trigger: 'change' }
          ],
          medicalTreatmentCoefficient: [
            { required: true, message: '请输入医疗保险系数', trigger: 'change' }
          ],
          unemploymentCoefficient: [
            { required: true, message: '请输入失业保险系数', trigger: 'change' }
          ],
          providentFundBase: [
            { required: true, message: '请输入公积金缴费基数', trigger: 'change' }
          ],
          providentFundCoefficient: [
            { required: true, message: '请输入住房公积金系数', trigger: 'change' }
          ],
          welfareFee: [
            { required: true, message: '请输入福利', trigger: 'change' }
          ],
          datePay: [
            { required: true, message: '请选择发放日期', trigger: 'change' }
          ]
        },
        visible: false,
        socialInsuranceBase: '',
        providentFundBase: '',
        restCoefficient: '',
        medicalTreatmentCoefficient: '',
        unemploymentCoefficient: '',
        providentFundCoefficient: '',
        idNumber: '',
        MonthlyWages: {}
      }
    },
    created() {
      this.teamRowClear = JSON.parse(JSON.stringify(this.teamRow))
      this.fetchData()
    },
    computed: {
      global() {
        return global
      },
      teamId() {
        return this.$store.state.user.teamId
      },
      teamName() {
        return this.$store.state.user.teamName
      }
    },
    methods: {
      fetchData() {
        this.searchFormList.pageNum = this.pageNum
        this.searchFormList.pageSize = this.pageSize
        this.listLoading = true
        getEmployeePayList(this.searchFormList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          console.log(this.tableData)
          this.listLoading = false
        })
      },
      getScheduleData() {
        const moneyParams = {
          startTime: this.monthForm.startTime,
          endTime: this.monthForm.endTime,
          idNumber: this.idNumber
        }
        this.scheduleLoading = true
        getMonthlyWages(moneyParams).then(response => {
          this.scheduleData = response.responseBody
          this.scheduleLoading = false
        })
      },
      search() {
        this.pageNum = 1
        this.searchFormList = JSON.parse(JSON.stringify(this.searchForm))
        this.fetchData()
      },
      searchMonthForm() {
        this.getScheduleData()
      },
      addTeam() {
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.outerVisible = true
        this.dialogTitle = '新增人员工资支出'
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        this.socialInsuranceBase = ''
        this.restCoefficient = ''
        this.medicalTreatmentCoefficient = ''
        this.unemploymentCoefficient = ''
        this.providentFundBase = ''
        this.providentFundCoefficient = ''
        this.dialogType = 1
        this.$set(this.teamRow, 'teamId', this.teamId)
        this.$set(this.teamRow, 'teamName', this.teamName)
      },
      editTeam(row) {
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.outerVisible = true
        this.dialogTitle = '修改人员工资支出'
        this.dialogType = 0
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        const params = {
          payId: row.payId
        }
        selectEmployeePay(params).then(response => {
          this.teamRow = response.responseBody
          this.socialInsuranceBase = response.responseBody.socialInsuranceBase
          this.restCoefficient = response.responseBody.restCoefficient
          this.medicalTreatmentCoefficient = response.responseBody.medicalTreatmentCoefficient
          this.unemploymentCoefficient = response.responseBody.unemploymentCoefficient
          this.providentFundBase = response.responseBody.providentFundBase
          this.providentFundCoefficient = response.responseBody.providentFundCoefficient
        })
        this.idNumber = row.idNumber
        this.getScheduleData()
      },
      selectSchedule(personId) {
        this.innerVisible = true
        const params = {
          personId: personId
        }
        selectMonthlyWages(params).then(response => {
          this.MonthlyWages = response.responseBody
        })
      },
      submitForm(formName) {
        const params = {
          teamId: this.teamRow.teamId,
          teamName: this.teamRow.teamName,
          employeeId: this.teamRow.employeeId,
          amount: this.teamRow.amount,
          compensationTime: this.teamRow.compensationTime,
          socialInsuranceBase: this.teamRow.socialInsuranceBase,
          restCoefficient: this.teamRow.restCoefficient,
          medicalTreatmentCoefficient: this.teamRow.medicalTreatmentCoefficient,
          unemploymentCoefficient: this.teamRow.unemploymentCoefficient,
          endowmentInsurance: this.teamRow.endowmentInsurance,
          doctorInsurance: this.teamRow.doctorInsurance,
          unemploymentInsurance: this.teamRow.unemploymentInsurance,
          workInsurance: this.teamRow.workInsurance,
          disabilityBenefits: this.teamRow.disabilityBenefits,
          providentFundBase: this.teamRow.providentFundBase,
          providentFundCoefficient: this.teamRow.providentFundCoefficient,
          welfareFee: this.teamRow.welfareFee,
          housingFund: this.teamRow.housingFund,
          maternity: this.teamRow.maternity ? this.teamRow.maternity : 0,
          unionExpenditure: this.teamRow.unionExpenditure ? this.teamRow.unionExpenditure : 0,
          individualincometax: this.teamRow.individualincometax ? this.teamRow.individualincometax : 0,
          datePay: this.teamRow.datePay
        }
        if (!this.dialogType) {
          params.payId = this.teamRow.payId
        }
        if (this.teamRow.teamId) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              if (this.dialogType) {
                addEmployeePay(params).then(response => {
                  console.log(response)
                  this.outerVisible = false
                  this.fetchData()
                })
              } else {
                updateEmployeePay(params).then(response => {
                  console.log(response)
                  this.outerVisible = false
                  this.fetchData()
                })
              }
            } else {
              console.log('error submit!!')
              return false
            }
          })
        } else {
          this.$message({
            message: '该团队不存在',
            type: 'warning'
          })
        }
      },
      deleteRow(scope) {
        this.$refs[`popover-${scope.$index}`].doClose()
        const params = {
          payId: scope.row.payId,
          isDel: 1
        }
        deleteEmployeePay(params).then(response => {
          this.fetchData()
        })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      },
      addressChange() {
        this.teamRow.provinceId = this.teamRow.addressId[0]
        this.teamRow.cityId = this.teamRow.addressId[1]
        this.teamRow.address = this.pca[86][this.teamRow.addressId[0]] + this.pca[this.teamRow.addressId[0]][this.teamRow.addressId[1]]
      },
      handleSelectProject(item) {
        this.$set(this.teamRow, 'projectId', item.projectId)
      },
      querySearchTeam(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        delete this.teamRow.teamId
        if (queryString) {
          const params = {
            teamName: queryString
          }
          selectTeam(params).then(response => {
            for (const i of response.responseBody) {
              i.value = i.teamName
            }
            let teamList = response.responseBody
            if (teamList.length === 0) {
              teamList = [{ value: '暂无数据' }]
            }
            callback(teamList)
          })
        } else {
          callback([])
        }
      },
      handleSelectTeam(item) {
        this.$set(this.teamRow, 'teamId', item.teamId)
      },
      querySearchName(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        if (queryString) {
          const params = {
            name: queryString,
            teamId: this.teamRow.teamId
          }
          selectEmployees(params).then(response => {
            for (const i of response.responseBody) {
              i.value = i.name
            }
            let nameList = response.responseBody
            if (nameList.length === 0) {
              nameList = [{ value: '暂无数据' }]
            }
            callback(nameList)
          })
        } else {
          callback([])
        }
      },
      handleSelectName(item) {
        this.teamRow.employeeId = item.employeeId
      },
      downloadFile() {
        this.$refs.file.click()
      },
      fileChanged() {
        const excel = this.$refs.file.value
        const params = new FormData()
        console.log(this.$refs.file.value)
        var reg = /^.*\.(?:xls|xlsx)$/i
        if (!reg.test(excel)) {
          Message({
            message: '请上传excel格式的文件!',
            type: 'error',
            duration: 5 * 1000
          })
          return
        } else {
          params.append('file', this.$refs.file.files[0])
          downloadMonthlyWages(params).then(response => {
            this.fetchData()
          })
          if (this.$refs.file) {
            this.$refs.file.value = ''
          }
        }
      }
    },
    mounted() {
      console.log(this.pca)
    },
    watch: {
      socialInsuranceBase: function(newQuestion, oldQuestion) {
        this.teamRow.socialInsuranceBase = newQuestion
        this.teamRow.doctorInsurance = parseFloat((this.medicalTreatmentCoefficient * newQuestion).toFixed(2))
        this.teamRow.workInsurance = 0
        this.teamRow.endowmentInsurance = parseFloat((this.restCoefficient * newQuestion).toFixed(2))
        this.teamRow.maternity = 0
        this.teamRow.unemploymentInsurance = parseFloat((this.unemploymentCoefficient * newQuestion).toFixed(2))
      },
      restCoefficient: function(newQuestion, oldQuestion) {
        this.teamRow.restCoefficient = newQuestion
        this.teamRow.endowmentInsurance = parseFloat((newQuestion * this.socialInsuranceBase).toFixed(2))
      },
      medicalTreatmentCoefficient: function(newQuestion, oldQuestion) {
        this.teamRow.medicalTreatmentCoefficient = newQuestion
        this.teamRow.doctorInsurance = parseFloat((newQuestion * this.socialInsuranceBase).toFixed(2))
      },
      unemploymentCoefficient: function(newQuestion, oldQuestion) {
        this.teamRow.unemploymentCoefficient = newQuestion
        this.teamRow.unemploymentInsurance = parseFloat((newQuestion * this.socialInsuranceBase).toFixed(2))
      },
      providentFundBase: function(newQuestion, oldQuestion) {
        this.teamRow.providentFundBase = newQuestion
        this.teamRow.housingFund = parseFloat((this.providentFundCoefficient * newQuestion).toFixed(2))
      },
      providentFundCoefficient: function(newQuestion, oldQuestion) {
        this.teamRow.providentFundCoefficient = newQuestion
        this.teamRow.housingFund = parseFloat((newQuestion * this.providentFundBase).toFixed(2))
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .app-container {
    .el-pagination {
      margin-top: 20px;
    }
    .table-btn {
      margin-bottom: 10px;
      & > button {
        margin: 0 20px;
      }
      .el-dialog {
        textarea {
          margin-top: 10px;
        }
        .el-checkbox {
          margin-right: 20px;
        }
        .el-checkbox + .el-checkbox {
          margin-left: 0;
        }
        .item-inline {
          display: inline-block;
          width: 400px;
        }
      }
    }
    .file {
      display: none;
    }
  }
</style>

<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  .inner-dialog {
    .item-inline {
      display: inline-block;
      width: 200px;
    }
  }

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
